﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace WindowsGame1
{
    public class StateShootSingle : State
    {
        public Vector2 target;
        public Vector2 offset;
        public float fov = 0;
        public int count = 1;

        public StateShootSingle(Alien a)
            : base(a)
        {

        }

        public override bool Update(Timer t)
        {
            Vector2 start = alien.pos + offset;
            Vector2 dir = Vector2.Normalize(target - start);

            float f = -fov * 0.5f;
            float s = fov / (count + 1);

            for (int i = 1; i <= count; i++)
            {
                float a = f + i * s;
                Matrix rot = Matrix.CreateRotationZ( MathHelper.ToRadians(a) );
                Vector3 dir3 = Vector3.Transform(new Vector3(dir.X, dir.Y, 0), rot);

                Bullet b = Bullet.CreateFatBullet();
                b.pos = start;
                b.dir = new Vector2(dir3.X, dir3.Y);
                b.owner = alien;
                Game1.instance.alienBulletManager.bullets.Add(b);
            }
            

            return false;
        }
    }
}
